﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BiliBiliCSharpStudy.clazz.ch26 {
    class OverrideExample {
        public static void Demo() {
            //Test1();
            Test2();
        }

        public static void Test2() {
            Vehicle v = new Car();
            v.Run();
            Console.WriteLine(v.Speed);
            var v1 = new Vehicle();
            v1.Run();
            Console.WriteLine(v1.Speed);
        }

        public static void Test1() {
            var car = new Car();
            car.Run();
            var v = new Vehicle();
            v.Run();

            //
            Vehicle v1 = new Car();
            v1.Run();

            //
            Vehicle v2 = new RaseCar();
            v2.Run();

            // 
            Type t = typeof(RaseCar);
            Console.WriteLine($"RaseCar base type is : {t.BaseType.FullName}");
        }
    }

    class Vehicle {
        private int _speed;
        public virtual int Speed {
            get {
                return _speed;
            }
            set {
                _speed = value;
            }
        }
        // 与 Java 不同，C#中必须书写 virtual 和 override 才算是重写
        // virtual
        public virtual void Run() {
            Console.WriteLine("I'm running!");
            _speed = 100;
        }
    }
    class Car : Vehicle {
        private int _rpm;
        public override int Speed {
            get {
                return _rpm / 100;
            }
            set {
                _rpm = value * 100;
            }
        }
        // override
        public override void Run() {
            Console.WriteLine("Car is running!");
            _rpm = 20000;
        }
    }

    class RaseCar : Car {
        public override void Run() {
            Console.WriteLine("Rase car is running!");
        }
    }
}
